package cn.com.pc.content.domain.tag;

import cn.com.pc.content.domain.content.ContentType;
import cn.com.pc.content.domain.Site;
import cn.com.pc.content.jpa.ContentTypeConverter;
import cn.com.pc.content.jpa.SiteConverter;
import cn.com.pc.content.jpa.TagIdsConverter;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import lombok.ToString;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.Set;

@Entity
@Table(name = "tag_histories")
@Data
@ToString
public class TagHistory {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(name = "content_id")
    private String contentId;

    @Column(name = "content_type")
    @Convert(converter = ContentTypeConverter.class)
    private ContentType contentType;

    @Column(name = "site")
    @Convert(converter = SiteConverter.class)
    private Site site;

    @Column(name = "tag_by")
    private String tagBy;

    @JsonFormat(timezone="GMT+8", pattern="yyyy-MM-dd HH:mm:ss", shape = JsonFormat.Shape.STRING)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @Column(name = "tag_at")
    private LocalDateTime tagAt;

    @Column(name = "tag_ids")
    @Convert(converter = TagIdsConverter.class)
    private Set<Long> tagIds;
}
